---
title: Structured data extraction 
---

Make sure you have installed LlamaIndex.TS and have an OpenAI key. If you haven't, check out the [installation](/docs/llamaindex/getting_started/installation) guide.

You can use [other LLMs](/docs/llamaindex/modules/models/llms) via their APIs; if you would prefer to use local models check out our [local LLM example](/docs/llamaindex/tutorials/local_llm).

## Set up

In a new folder:

```bash npm2yarn
npm init
npm i -D typescript @types/node
```

## Extract data

Create the file `example.ts`. This code will:

- Set up an LLM connection to GPT-4
- Give an example of the data structure we wish to generate
- Prompt the LLM with instructions and the example, plus a sample transcript

<include cwd>../../examples/jsonExtract.ts</include>

To run the code:

```bash
npx tsx example.ts
```

You should expect output something like:

```json
{
  "summary": "Sarah from XYZ Company called John to introduce the XYZ Widget, a tool designed to automate tasks and improve productivity. John expressed interest and requested case studies and a product demo. Sarah agreed to send the information and follow up to schedule the demo.",
  "products": ["XYZ Widget"],
  "rep_name": "Sarah",
  "prospect_name": "John",
  "action_items": [
    "Send case studies and additional product information to John",
    "Follow up with John to schedule a product demo"
  ]
}
```
